package com.vunguyen.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.vunguyen.model.Lichlamviec;


@Repository
public class LichLamViecDAOImpl implements LichLamViecDAO{
	
	@Autowired
	private SessionFactory sessionFactory;

	@SuppressWarnings("unchecked")
	@Override
	public List<Lichlamviec> getLichLamViec() {
		return sessionFactory.getCurrentSession().createQuery("From Lichlamviec").list();
	}

	@Override
	public void addLichLamViec(Lichlamviec lichlamviec) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(lichlamviec);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Lichlamviec> getListLichlamviecById(int idlichlamviec) {
		return sessionFactory.getCurrentSession().createQuery("from Lichlamviec where idLichLamViec='"+idlichlamviec+"'").list();
	}

	@Override
	public void updateLichLamViec(Lichlamviec lichlamviec, int idlichlamviec) {
		Session session = this.sessionFactory.getCurrentSession();
		Lichlamviec llv = (Lichlamviec) session.get(Lichlamviec.class, idlichlamviec);
		llv.setTuan(lichlamviec.getTuan());
		llv.setNgay(lichlamviec.getNgay());
		llv.setThoiGianBatDau(lichlamviec.getThoiGianBatDau());
		llv.setThoiGianKetThuc(lichlamviec.getThoiGianKetThuc());
		llv.setNoiDung(lichlamviec.getNoiDung());
		llv.setDiaDiem(lichlamviec.getDiaDiem());
		llv.setGhiChu(lichlamviec.getGhiChu());
		session.update(llv);
		
	}

	
	

	

}
